using System;
using System.Windows.Forms;
using CodePlex.TfsLibrary.ObjectModel;

namespace CodePlex.CodePlexClientLibrary
{
    public partial class StatusForm : Form, IStatusForm
    {
        public StatusForm()
        {
            InitializeComponent();

            statusListView.ItemAdd += OnItemAdd;
            statusListView.ItemDelete += OnItemDelete;
            statusListView.ItemDiff += OnItemDiff;
            statusListView.ItemDiffMineAgainstBase += OnItemDiffMineAgainstBase;
            statusListView.ItemDiffTheirsAgainstBase += OnItemDiffTheirsAgainstBase;
            statusListView.ItemMerge += OnItemMerge;
            statusListView.ItemRevert += OnItemRevert;
            statusListView.ItemResolve += OnItemResolve;
        }

        public string LocalPath
        {
            set
            {
                statusListView.BasePath = value;
                Text = "Status - " + value;
            }
        }

        public void DisplayItem(SourceItem item)
        {
            statusListView.DisplayItem(item);
        }

        public event EventHandler<EventArgs<SourceItem>> ItemAdd;
        public event EventHandler<EventArgs<SourceItem>> ItemDelete;
        public event EventHandler<EventArgs<SourceItem>> ItemDiff;
        public event EventHandler<EventArgs<SourceItem>> ItemDiffMineAgainstBase;
        public event EventHandler<EventArgs<SourceItem>> ItemDiffTheirsAgainstBase;
        public event EventHandler<EventArgs<SourceItem>> ItemMerge;
        public event EventHandler<EventArgs<SourceItem>> ItemResolve;
        public event EventHandler<EventArgs<SourceItem>> ItemRevert;

        void OnItemAdd(object sender,
                       EventArgs<SourceItem> e)
        {
            if (ItemAdd != null)
                ItemAdd(sender, e);
        }

        void OnItemDelete(object sender,
                          EventArgs<SourceItem> e)
        {
            if (ItemDelete != null)
                ItemDelete(sender, e);
        }

        void OnItemDiff(object sender,
                        EventArgs<SourceItem> e)
        {
            if (ItemDiff != null)
                ItemDiff(sender, e);
        }

        void OnItemDiffMineAgainstBase(object sender,
                                       EventArgs<SourceItem> e)
        {
            if (ItemDiffMineAgainstBase != null)
                ItemDiffMineAgainstBase(sender, e);
        }

        void OnItemDiffTheirsAgainstBase(object sender,
                                         EventArgs<SourceItem> e)
        {
            if (ItemDiffTheirsAgainstBase != null)
                ItemDiffTheirsAgainstBase(sender, e);
        }

        void OnItemMerge(object sender,
                         EventArgs<SourceItem> e)
        {
            if (ItemMerge != null)
                ItemMerge(sender, e);
        }

        void OnItemResolve(object sender,
                           EventArgs<SourceItem> e)
        {
            if (ItemResolve != null)
                ItemResolve(sender, e);
        }

        void OnItemRevert(object sender,
                          EventArgs<SourceItem> e)
        {
            if (ItemRevert != null)
                ItemRevert(sender, e);
        }

        public void RemoveItem(string localName)
        {
            statusListView.RemoveItem(localName);
        }
    }
}